﻿using System;
using System.Collections.Generic;
using System.Web;

namespace Travel.Web.ashx
{
    /// <summary>
    /// routeHandles 的摘要说明
    /// </summary>
    public class routeHandles : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            switch (context.Request["method"])
            {
                case "getImage":
                    context.Response.Write(GetImage(context.Request["id"]));
                    break;
                case "addImage":
                    context.Response.Write(AddImage(Convert.ToInt32(context.Request["id"]),
                        context.Request["imageUrl"], context.Request["name"]));
                    break;
                case "removeImage":
                    context.Response.Write(RemoveImage(new Guid(context.Request["id"])));
                    break;
                case "addPrice":
                    break;
                case "updatePrice":
                    break;
                case "removePrice":
                    break;
            }
        }

        private string GetImage(string id)
        {
            BLL.route_image routeImage = new BLL.route_image();
            var imageList = routeImage.GetModelList(string.Format("route_id={0}", id));

            return Newtonsoft.Json.JsonConvert.SerializeObject(imageList);
        }

        private bool AddImage(int id, string imageUrl, string name)
        {
            BLL.route_image routeImage = new BLL.route_image();
            Model.route_image image = new Model.route_image();
            image.route_id = id;
            image.name = name;
            image.url = imageUrl;

            return routeImage.Add(image);
        }

        private bool RemoveImage(Guid id)
        {
            BLL.route_image routeImage = new BLL.route_image();
            return routeImage.Delete(id);
        }

        private bool AddPrice(int id,DateTime dateTime,decimal routePrice,string code)
        {
            BLL.route_price price = new BLL.route_price();
            Model.route_price priceModel = new Model.route_price();

            priceModel.route_id = id;
            priceModel.userd_date = dateTime;
            //priceModel = routePrice;
            priceModel.code = code;


            return price.Add(priceModel);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}